package com.qf.service.impl;

import com.qf.entity.Menu;
import com.qf.mapper.MenuMapper;
import com.qf.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuMapper menuMapper;
    @Override
    public List<Menu> findAllInfo() {
        List<Menu> menuList = menuMapper.selectAll();
        //存放一级菜单的集合
        ArrayList firstMenu = new ArrayList();
        for (Menu menu : menuList) {
            if(menu.getUpMenuId()==0){
                //存放二级菜单的集合
                ArrayList secondMenu = new ArrayList();
                for (Menu second : menuList) {
                    if(menu.getMenuId()==second.getUpMenuId()){
                        secondMenu.add(second);
                    }
                }
                //将二级菜单封装到一级菜单中
                menu.setSecondMenu(secondMenu);
                //将一级菜单存放到集合中
                firstMenu.add(menu);
            }
        }
        return firstMenu;
    }
}
